import {exportWord} from "@/components/exportFunction";
import {serverList} from "@/api/server";


export const exportMixin = {
    data() {
        return{
            exportVisible: false,
            exportForm: {
                name : '',
                height : null,
                width : null,
                module : ''
            },
            exportRules: {
                name: [
                    {required: true, message: '请输入导出文件名', trigger: 'blur'},
                ],
                height: [
                    {required: true, message: '请输入图片高度', trigger: 'blur'},
                ],
                width: [
                    {required: true, message: '请输入图片宽度', trigger: 'blur'},
                ],
            }
        }
    },
    methods : {
        startExport(module,data,dataName,extraData = null,extraDataName = null,graph = [],graphData = []) {
            this.exportForm.module = module
            exportWord(this.exportForm.height,this.exportForm.width,this.exportForm.name,this.exportForm.module,data,dataName,graph,graphData,extraData,extraDataName)
        }
    }
}
export const mixin = {
    methods:{
        handleCurrentChange(val) {
            this.currentPage = val
        }
    },
    data() {
        return{
            total: '',
            currentPage:1,
            pageSize: 10,
        }
    }
}
// login和sidebar2组件均要用到的方法
export const serverSelectionMixin = {
    methods: {
        // 改变时vuex内容同步
        serverChange(index) {
            // this.$serverName.setserverName(this.serverList[index - 1].label)
            // console.log('?',this.$serverName.serverName);
            this.$store.commit("changeServerName",this.serverList[index - 1].label)
            this.$store.commit("changeServerId",this.serverList[index - 1].value)
        },
        // 服务器数据获取
        serverData() {
            serverList().then(res=>{
            // axios.get(this.$ip2 + '/server/list/').then(res=>{
                this.serverList =[]
                for (let i =0;i<res.data.length;i++){
                    this.serverList.push({
                        value:res.data[i].server_id,
                        label:res.data[i].server_id + ':' + res.data[i].server_name
                    })
                }
                this.$store.commit("changeServerList",this.serverList)
            })
        }
    }
}
